package com.evan.framework.core.base;

import com.evan.common.base.BaseEnumInterface;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: 基础枚举
 * @Author liudeguang
 */
public enum BaseEnum implements BaseEnumInterface<String> {

    SUCCESS("000000", "成功"),
    PARAM_NULL("000001", "参数为空"),
    PARAM_ERROR("000002", "参数错误"),
    PARAM_NOT_DIGITAL("000003", "参数非数字"),
    PARAMGT0("000004", "参数大于0"),
    PARAMLT0("000005", "参数小于0"),
    PARAM_EMPTY("000006", "参数为空"),
    DATA_NOT_EXIST("000007", "数据不存在"),
    DATA_IS_EXIST("000008", "数据已存在"),
    DB_ERROR("000009", "数据异常"),
    DUPLICATE_OPERATION("000010", "重复操作"),
    SERIALIZATION_EXCEPTION("000011", "序列化操作异常"),
    INSTANTIATION_ERROR("000012", "实例化异常"),
    CLASSCAST_ERROR("000013", "类型转换异常"),
    AUTH_EXCEPTION("000014", "认证服务异常"),
    INVALID_TOKEN("000015", "无效token"),
    PERMISSION_DENIED("000016", "权限不足"),
    SIGNATURE_ERROR("000017", "签名错误"),
    UNKNOWN("000017", "未知异常"),
    FAIL("999999", "失败");

    /**
     * 枚举CODE
     */
    private String code;
    /**
     * 枚举描述信息
     */
    private String desc;

    BaseEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;

    }

    public final static Map<String, BaseEnum> MAP_VALUES = Arrays.stream(BaseEnum.values()).collect(Collectors.toMap(e -> e.code, e -> e, (e1, e2) -> e1));

    public static Boolean containCode(String code) {
        return MAP_VALUES.containsKey(code);
    }

    public static BaseEnum getByCode(String code) {
        return MAP_VALUES.get(code);
    }

}
